package com.qujia.station.controller;

import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.core.page.TableDataInfo;
import com.qujia.common.utils.poi.ExcelUtil;
import com.qujia.station.domain.form.FinanceStatementQueryForm;
import com.qujia.station.domain.vo.FinanceStatement;
import com.qujia.station.service.IFinanceStatementService;
import com.qujia.station.task.SaticScheduleTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

/**
 * @description finance_statements_station
 * @author
 * @date 2023-07-04
 */
@Api(value = "财务报表接口")
@RestController
@RequestMapping(value = "/financeStatement")
public class FinanceStatementController extends BaseController {

    @Autowired
    private IFinanceStatementService financeStatementService;
    @Autowired
    private SaticScheduleTask scheduleTask;

    @GetMapping("today")
    @ApiOperation("今日统计")
    public AjaxResult queryTodayStatement(FinanceStatementQueryForm form){
        LocalDate today = LocalDate.now();
        form.setBeginDate(LocalDateTime.of(today, LocalTime.of(0,0,0)));
        form.setEndDate(LocalDateTime.of(today,LocalTime.of(23,59,59)));
        FinanceStatement statement = financeStatementService.countStatementByDate(form);
        return AjaxResult.success(statement);
    }

    @GetMapping("history")
    @ApiOperation("历史统计")
    public TableDataInfo queryHistoryStatement(FinanceStatementQueryForm form){
        startPage();
        List<FinanceStatement> list = financeStatementService.queryHistoryStatement(form);
        return getDataTable(list);
    }

    @GetMapping("history/export")
    @ApiOperation("历史记录导出")
    public AjaxResult exportHistoryStatement(FinanceStatementQueryForm form){
        List<FinanceStatement> list = financeStatementService.queryHistoryStatement(form);
        ExcelUtil<FinanceStatement> util = new ExcelUtil<>(FinanceStatement.class);
        return util.exportExcel(list, "财务报表");
    }
}